package com.munhrasoft.elearning.business.logic;

import java.util.List;
import java.util.logging.Logger;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.munhrasoft.elearning.business.entities.Courses;

@Stateless
public class CoursesEJB {

    private static Logger logger = Logger.getLogger(CoursesEJB.class.getName());

    @PersistenceContext(unitName = "elearningPU")
    private EntityManager em;

    @SuppressWarnings("unchecked")
    public List<Courses> findCoursesByTitle(String name) {
        Query query = em.createNamedQuery("findCoursesByTitle");
        query.setParameter("title", name.toLowerCase() + "%");
        return query.getResultList();
    }

    @SuppressWarnings("unchecked")
    public List<Courses> findAllCourses() {
        Query query = em.createNamedQuery("findAllCourses");
        return query.getResultList();
    }

}
